package sxe.core.math;

import snobject.snDouble;
import snobject.snObject;
import snobject.snObjectArgList;
import step.FunctionWrapper;
import step.EvaluationFailure;
import sxe.core.EvaluationFailureReasons;

/**
 * Returns the value of the first argument raised to the power of the second argument. 
 * @param argv must contain two snDouble objects at top of the stack
 * @return returns the value a^b
 */

public class pow extends FunctionWrapper{
	
	public snObject Call(snObjectArgList argv) throws EvaluationFailure{
		// REQUIRES: argv must contain two snDouble object at top of the stack
		// EFFECTS:	if argv contains less than 2 objects, throw EvaluationFailure exception
		//			otherwise returns the snDouble of the value a^b
		if(argv.length()<2)
			throw new EvaluationFailure(super.expnode,
					EvaluationFailureReasons.BAD_PARAMETER_COUNT);
		
		double ret1 = argv.popDouble().getDbl();
		double ret2 = argv.popDouble().getDbl();
		
		return new snDouble(Math.pow(ret1, ret2));
	}
}